package com.dk.controller;

import com.dk.pojo.TDep;
import com.dk.service.TDepServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tDepController")
public class TDepController {

    //部门
    @Autowired
    private TDepServiceI tDepServiceI;

    //跳转部门查询页
    @RequestMapping("list")
    public String listGet(){
        return "dep/list";
    }
    //部门表查询
    @RequestMapping("getInfoServer")
    @ResponseBody
    public List<TDep> getInfoServer(){
        List<TDep> list = tDepServiceI.getInfoServer();
        return list;
    }

    //跳转增加部门表页面
    @RequestMapping("insertInfo")
    public String insertInfo(){
        return "dep/add";
    }

    //确认增加
    @RequestMapping("saveById")
    @ResponseBody
    public int saveById(TDep tDep){
        tDepServiceI.saveById(tDep);
        return 1;
    }

    //删除
    @RequestMapping("deleteById/{depId}")
    @ResponseBody
    public int deleteById(@PathVariable("depId")Integer depId){
        tDepServiceI.deleteById(depId);
        return 1;
    }

    //修改部门表回显
    @RequestMapping("updateInfo/{depId}")
    public String updateInfo(@PathVariable("depId")Integer depId, Model model){
        TDep tDep = tDepServiceI.getNameById(depId);
        model.addAttribute("tDep",tDep);
        return "dep/update";
    }

    //确认修改
    @RequestMapping("updateById")
    @ResponseBody
    public int updateById(TDep tDep){
        tDepServiceI.updateById(tDep);
        return 1;
    }
}
